package me.itsoo.artemis.framework.core.converter.datetime;

import me.itsoo.artemis.framework.core.collect.ImmutableMap;
import me.itsoo.artemis.framework.core.converter.TypeConvertor;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Date;
import java.util.Map;

/**
 * ChronoTypeConvertor
 *
 * @author zxy
 * @version 0.0.1
 * @since 2023/5/18
 */
public interface ChronoTypeConvertor extends TypeConvertor {

    /**
     * 日期类型转换器
     */
    Map<Class<?>, ChronoTypeConvertor> TYPE_CONVERTORS = ImmutableMap.<Class<?>, ChronoTypeConvertor>builder()
            .put(Date.class, new DateTypeConvertor())
            .put(LocalDate.class, new LocalDateTypeConvertor())
            .put(LocalTime.class, new LocalTimeTypeConvertor())
            .put(LocalDateTime.class, new LocalDateTimeTypeConvertor())
            .build();

    /**
     * 类型转换
     *
     * @param value  Object
     * @param format String
     * @return Object
     */
    Object convertIfNecessary(Object value, String format);

}
